/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaProfesor.java
 *
 * Created on 13/02/2011, 03:57:43 PM
 */
package Matricula_Nota;

import java.util.ArrayList;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Pedro
 */
public final class VistaProfesorCurso extends javax.swing.JDialog {

    private ArrayList<Profesor> profesores;
    private DefaultTableModel mdlProfesores;
    private Curso curso;
    private Coordinador coordinador;
    private Area area;
    private ArrayList<String> dniProfesores;

    /** Creates new form VistaProfesor */
    public VistaProfesorCurso(javax.swing.JDialog parent, boolean modal, Curso curso, Area area, Coordinador coordinador) {
        super(parent, modal);
        initComponents();
        this.curso = curso;
        this.coordinador = coordinador;
        this.area = area;

        dniProfesores = new ArrayList<String>();
        profesores = coordinador.getProfesores();

        for (Profesor profe : profesores) {
            cboProfesores.addItem(profe.getNombre() + " " + profe.getApellido());
            dniProfesores.add(profe.getDni());
        }
        mdlProfesores = (DefaultTableModel) tblProfesores.getModel();
        tblProfesores.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
        mostrarProfesores();
    }

    public void mostrarProfesores() {
        mdlProfesores.setRowCount(curso.getProfesores().size());
        for (int i = 0; i < curso.getProfesores().size(); i++) {
            Profesor profe = curso.getProfesores().get(i);
            mdlProfesores.setValueAt(profe.getDni(), i, 0);
            mdlProfesores.setValueAt(profe.getNombre(), i, 1);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        cboProfesores = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        btnAgregarProfesor = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblProfesores = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Profesores por Curso");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Agregar Profesor al Curso"));

        cboProfesores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboProfesoresActionPerformed(evt);
            }
        });

        jLabel1.setText("Profesores Disponibles :");

        btnAgregarProfesor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Add.png"))); // NOI18N
        btnAgregarProfesor.setToolTipText("Agregar");
        btnAgregarProfesor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarProfesorActionPerformed(evt);
            }
        });

        tblProfesores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nombre", "Estado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblProfesores);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(cboProfesores, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAgregarProfesor))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(cboProfesores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnAgregarProfesor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarProfesorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarProfesorActionPerformed
        try {
            int indProfe = cboProfesores.getSelectedIndex();
            Profesor profe = coordinador.buscarProfesor(dniProfesores.get(indProfe));
//            System.out.println("numero dni buscar ==> " + dniProfesores.get(indProfe));
//            System.out.println("Indice de busqueda ==> " + indProfe);
            coordinador.registrarProfesorCurso(area, curso, profe);
            mostrarProfesores();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage());
        }
}//GEN-LAST:event_btnAgregarProfesorActionPerformed

    private void cboProfesoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboProfesoresActionPerformed
    }//GEN-LAST:event_cboProfesoresActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarProfesor;
    private javax.swing.JComboBox cboProfesores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblProfesores;
    // End of variables declaration//GEN-END:variables
}
